package com.asset.dispoal.file.bank;

import com.asset.dispoal.file.bank.api.FileBankService;
import com.asset.dispoal.file.bank.dto.FileBankDetailPageRequest;
import com.asset.dispoal.file.bank.dto.FileBankDetailRequest;
import com.asset.dispoal.file.bank.dto.FileBankExportRequest;
import com.asset.dispoal.file.bank.dto.FileBankPageRequest;
import com.asset.dispoal.file.bank.dto.FileBankRequest;
import com.asset.dispoal.file.bank.dto.FileBankStatisticsRequest;
import com.asset.dispoal.file.bank.dto.FileBankStatisticsResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import tech.mhuang.pacebox.core.util.StringUtil;
import tech.mhuang.pacebox.springboot.protocol.Result;

import javax.servlet.http.HttpServletResponse;

@RestController
@Api(value = "银行管理", tags = "银行管理")
@RequestMapping("file/bank")
public class FileBankController {
    @Autowired
    private FileBankService fileBankService;

    @PostMapping("/save")
    public Result save(@RequestBody FileBankRequest request) {
        return fileBankService.save(request);
    }

    @PostMapping("/modify")
    public Result modify(@RequestBody FileBankRequest request) {
        return fileBankService.modify(request);
    }

    @PostMapping("/page")
    public Result page(@RequestBody FileBankPageRequest request) {
        return fileBankService.page(request);
    }

    @PostMapping("/queryStatistics")
    public Result<FileBankStatisticsResponse> queryStatistics(@RequestBody FileBankStatisticsRequest statisticsRequest) {
        return fileBankService.queryStatistics(statisticsRequest);
    }

    @GetMapping("/delete")
    public Result delete(String id) {
        if (StringUtil.isBlank(id)) {
            return Result.faild("配置id为空，请检查！！");
        }
        return fileBankService.delete(id);
    }

    @ApiOperation(value = "上传路径", notes = "上传路径")
    @GetMapping(value = "/uploadExcel")
    public Result uploadExcel(@ApiParam("文件路径") @RequestParam("filepath") String filepath) {
        fileBankService.uploadExcel(filepath);
        return Result.ok();
    }

    @PostMapping("/saveDetail")
    public Result saveDetail(@RequestBody FileBankDetailRequest request) {
        return fileBankService.saveDetail(request);
    }

    @PostMapping("/modifyDetail")
    public Result modifyDetail(@RequestBody FileBankDetailRequest request) {
        return fileBankService.modifyDetail(request);
    }

    @GetMapping("/queryByLevel")
    public Result queryByLevel() {
        return fileBankService.queryByLevel();
    }

    @GetMapping("/queryByLevelAmount")
    public Result queryByLevelAmount() {
        return fileBankService.queryByLevelAmount();
    }

    @GetMapping("/queryDetailStatistics")
    public Result queryDetailStatistics(String bankId) {
        return fileBankService.queryDetailStatistics(bankId);
    }

    @PostMapping("/pageDetail")
    public Result pageDetail(@RequestBody FileBankDetailPageRequest request) {
        return fileBankService.pageDetail(request);
    }


    @GetMapping("/deleteDetail")
    public Result deleteDetail(String id) {
        if (StringUtil.isBlank(id)) {
            return Result.faild("配置id为空，请检查！！");
        }
        return fileBankService.deleteDetail(id);
    }

    @ApiOperation(value = "上传路径", notes = "上传路径")
    @GetMapping(value = "/uploadDetailExcel")
    public Result uploadDetailExcel(@ApiParam("文件路径") @RequestParam("filepath") String filepath, @RequestParam("bankId") String bankId) {
        fileBankService.uploadDetailExcel(filepath, bankId);
        return Result.ok();
    }

    @GetMapping("queryAll")
    public Result queryAll() {
        return fileBankService.queryAll();
    }

    @GetMapping("/getById")
    public Result getById(String id) {
        return fileBankService.getById(id);
    }

    @ApiOperation(value = "导出", notes = "导出")
    @GetMapping(value = "/export")
    public void export(HttpServletResponse response, FileBankExportRequest request) {
        fileBankService.export(response, request);
    }
}